\documentclass{article}
\usepackage[top=1cm, bottom=1cm, left=1cm, right=1cm]{geometry}

% \checkandfixthelayout
% \documentclass[a4paper]{article}
\usepackage[linesnumbered,ruled,vlined,algo2e]{algorithm2e}
% \SetAlgoLined：增添end行
% \DontPrintSemicolon：不显示行末尾的分号
% \SetKwInput{KwInput}{Input}：设置输入
% \SetKwInOut{KwInput}{Input}：设置输入输出
% ruled：标题左对齐，顶部和底部各添加一条线
% linesnumbered：显示行编号
\usepackage{ctex} %注意，这里必须引入ctex,否则中文内容无法输出
\SetKwRepeat{Do}{do}{while}

\begin{document}

\begin{algorithm2e}[H]
    \caption{API 分析数据处理算法}
    \KwIn{library\_name, file\_name, function\_name, file\_path, source\_code}
    \KwOut{api\_r 或 s（API 分析结果）}

    % 查询数据库中是否存在现有文件记录
    \SetAlgoLined
    existing\_file $\gets$ self.session.query(API\_Analysis).filter(\\
        \Indp
        API\_Analysis.library\_name $==$ library\_name,\\
        API\_Analysis.file\_name $==$ file\_name,\\
        API\_Analysis.function\_name $==$ function\_name,\\
        API\_Analysis.file\_path $==$ file\_path,\\
        API\_Analysis.source\_code $==$ source\_code\\
        \Indm
    ).first()
    % \Indp
    % \ForEach{条件 $c$ in \{API\_Analysis.library\_name $==$ library\_name, API\_Analysis.file\_name $==$ file\_name, API\_Analysis.function\_name $==$ function\_name, API\_Analysis.file\_path $==$ file\_path, API\_Analysis.source\_code $==$ source\_code\}}{
    %     existing\_file $\gets$ existing\_file.filter($c$) \;
    % }
    % \Indm
    % existing\_file $\gets$ existing\_file.first() \;

    \If{existing\_file is None}
    {
        $ api\_r=analysis\_API\_document(library\_name,file\_name,function\_name,file\_path) $
    }
    \If{existing\_file is None}{
        % 创建新的 API 分析记录
        generated\_file $\gets$ API\_Analysis( \;
        \Indp
        library\_name $=$ library\_name, \;
        file\_name $=$ file\_name, \;
        function\_name $=$ function\_name, \;
        file\_path $=$ file\_path, \;
        source\_code $=$ source\_code \;
        \Indm
        ) \;
    }

\end{algorithm2e}

\end{document}    